home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / strings.arc / STRINGS.C next >
Encoding:
C/C++ Source or Header  |  1986-06-17  |  1.3 KB  |  77 lines

  1. /* strings.c */
  2.  
  3. #include <stdio.h>
  4. #define DESMET
  5.  
  6. /* #define DEBUG */
  7.  
  8. static char ver[] = "DeSmet C";
  9.  
  10. #define LIMIT    3
  11. #define MAXLINE    200
  12.  
  13. int num_printable = 0;
  14. char line[MAXLINE + 10]; /* ten extra for slop jht */
  15.  
  16. main(argc,argv)
  17. int argc;
  18. char *argv[];
  19. {
  20. FILE *input;
  21. int c;
  22.  
  23.     if (argc < 2) {
  24.         puts("Usage: strings filename\n");
  25.         exit(1);
  26.     }
  27.  
  28.     if ((input = fopen(argv[1],"rb")) == NULL) {
  29.         puts("Can't open "); puts(argv[1]);
  30.         exit(1);
  31.     }
  32.  
  33.     while ((c = getc(input)) != EOF) {
  34.         if (num_printable < MAXLINE && (c >= ' ' && c <= '~') || c == '\n' || c == '\r' || c == '\t')
  35.             line[num_printable++] = c;
  36.         else {
  37.             if (num_printable > LIMIT) {
  38.  
  39. #ifdef DEBUG
  40.                 printd(num_printable);
  41.                 puts(" chars :");
  42. #endif
  43.  
  44.                 line[num_printable] = '\0';
  45.                 puts(line);
  46. #ifdef DESMET
  47.                 putchar('\n');
  48. #endif
  49.             }
  50.             num_printable = 0;
  51.         } /* else */
  52.     } /* while */
  53.  
  54.     if (num_printable > LIMIT) {
  55.         line[num_printable] = '\0';
  56.         puts(line);
  57. #ifdef DESMET
  58.         putchar('\n');
  59. #endif
  60.     }
  61. } /* main */
  62.  
  63. #ifdef DEBUG
  64.  
  65. printd(n) /* print n in decimal (recursive) */
  66. int    n;
  67. {
  68.     int    i;
  69.  
  70.     if ((i = n / 10) != 0)
  71.         printd(i);
  72.     putchar(n % 10 + '0');
  73. }
  74.  
  75. #endif
  76.